import axios, { AxiosRequestConfig } from 'axios'

import { IMsgDetail, IMsgListRes, ISearch, ISendValues, ITemplate, ITemplateRes } from '../interface'
import './__mock__'
/** 新增消息模板 */
export const apiPostMsgManageAdd = async (
  req: Omit<ISendValues, 'messageId'>,
  signal?: AxiosRequestConfig['signal'],
): Promise<{ success: boolean; errorMsg: string }> => {
  return axios.post(`/tmsapi/message_manage/add`, req, { signal }).then(res => res.$data)
}

/** 消息模板列表 */
export const apiGetMsgManageList = async (
  req: ISearch,
  signal?: AxiosRequestConfig['signal'],
): Promise<IMsgListRes> => {
  return axios.post(`/tmsapi/message_manage/list`, req, { signal }).then(res => res.$data)
}

/** 消息模板详情 */
export const apiGetDetail = async (messageId: string): Promise<IMsgDetail> => {
  return axios.post(`/tmsapi/message_manage/detail`, { messageId }).then(res => res.$data)
}

/** 更新消息通知 */
export const apiUpdateMsgList = async (
  req: ISendValues,
  signal?: AxiosRequestConfig['signal'],
): Promise<{ success: boolean; errorMsg: string }> => {
  return axios.post(`/tmsapi/message_manage/update`, req, { signal }).then(res => res.$data)
}

/** 删除消息通知 */
export const apiDeleteMsg = async (messageId: string): Promise<void> => {
  return axios.post(`/tmsapi/message_manage/del`, { messageId }).then(res => res.$data)
}

/** 邮件模板列表 */
export const apiGetTemplateList = async (
  req: ISearch,
  signal?: AxiosRequestConfig['signal'],
): Promise<ITemplateRes> => {
  return axios.post(`/tmsapi/template/list`, req, { signal }).then(res => res.$data)
}

/** 邮件模板 */
export const apiGetTemplate = async (templateId: string): Promise<ITemplate | null> => {
  return axios.post(`/tmsapi/template/getTemplate`, { templateId }).then(res => res.$data ?? null)
}
